import useDictStore from '@/store/modules/dict' 
import service from '@/utils/request'

/**
 * 获取字典数据
 */
export async function useDict(...args) {
  const res = ref({});
  for (let index = 0; index < args.length; index++) {
    const dictType = args[index]
    res.value[dictType] = [];
    const dicts = useDictStore().getDict(dictType);  
    if (dicts != null || dicts != undefined) {
      res.value[dictType] = dicts;
    } else {
      const resp = await service.get('/shipping/dict/data/type/'+dictType)
      res.value[dictType] = resp.data.map(p => ({ label: p.dictLabel, value: p.dictValue,dictDesc:p.dictDesc  })) 
      useDictStore().setDict(dictType, res.value[dictType]);
    }
  }
  return toRefs(res.value);
}